
<?php
session_start();
include_once("../../untils/conn.php");
mysqli_query($con, "set names utf8");

// 获取当前正在登录的账号信息的代理
$proxy_acc = $_SESSION["account"];

$sql = "SELECT proxy_id FROM proxy WHERE proxy_acc = '$proxy_acc'";
$result = mysqli_query($con, $sql);

if ($result) {
    $row = mysqli_fetch_assoc($result);
    $proxy_id = $row['proxy_id'];
}

$searchValue = $_POST['searchValue'];

// 判断是否为手机号
if (preg_match('/^1[3456789]\d{9}$/', $searchValue)) {
  // 查询订单表中手机号为$searchValue的订单信息
  $sql = "SELECT * FROM oder WHERE phone = '$searchValue'";
  $result = mysqli_query($con, $sql);
  if (mysqli_num_rows($result) > 0) {
    $row = mysqli_fetch_assoc($result);
    $data = [
      'oderid' => $row['oderid'], 
      'phones' => $row['phone'],
      'uid' => $row['uid'],
      'status' => $row['status'],
      'name' => $row['name'],
      'time' => date('Y-m-d H:i:s', $row['time']),
      
      'tgaccount' => $proxy_acc,
      'goods' => $row['goods'],
      'thirdphone' => $row['thirdphone'],
      'iccid' => $row['iccid'],
      'notes'=> $row['beizhu']
    ];
    echo json_encode($data);
  } else {
    // 手机号没有对应的订单
    $msg = '没有找到对应的订单';
    $response = [
      'status' => 'error',
      'msg' => $msg
    ];
    echo json_encode($response);
  }
}
// 判断是否为身份证号
else if (preg_match('/^\d{17}[\d|x]|\d{15}$/', $searchValue)) {
  // 查询订单表中身份证号为$searchValue的订单信息
  $sql = "SELECT * FROM oder WHERE uid = '$searchValue'";
  $result = mysqli_query($con, $sql);
  if (mysqli_num_rows($result) > 0) {
    $row = mysqli_fetch_assoc($result);
    //   $xdtime = $row['time'];
       
    $data = [
      'oderid' => $row['oderid'], 
      'phones' => $row['phone'],
      'uid' => $row['uid'],
      'status' => $row['status'],
      'name' => $row['name'],
      'time' => date('Y-m-d H:i:s', $row['time']),
      
      'tgaccount' => $proxy_acc,
      'goods' => $row['goods'],
      'thirdphone' => $row['thirdphone'],
      'iccid' => $row['iccid'],
      'notes'=> $row['beizhu']
    ];
    echo json_encode($data);
  } else {
    // 身份证号没有对应的订单
    $msg = '没有找到对应的订单';
    $response = [
      'status' => 'error',
      'msg' => $msg
    ];
    echo json_encode($response);
  }
}
// 判断是否为订单号
else if (strpos($searchValue, 'KJKJ') === 0) {
  // 查询订单表中订单号为$searchValue的订单信息
  $sql = "SELECT * FROM oder WHERE oderid = '$searchValue'";
  $result = mysqli_query($con, $sql);
  if (mysqli_num_rows($result) > 0) {
    $row = mysqli_fetch_assoc($result);
    $data = [
      'oderid' => $row['oderid'], 
      'phones' => $row['phone'],
      'uid' => $row['uid'],
      'status' => $row['status'],
      'name' => $row['name'],
      'time' => date('Y-m-d H:i:s', $row['time']),
      
      'tgaccount' => $proxy_acc,
      'goods' => $row['goods'],
      'thirdphone' => $row['thirdphone'],
      'iccid' => $row['iccid'],
      'notes'=> $row['beizhu']
    ];
    echo json_encode($data);
  } else {
    // 订单号没有对应的订单
    $msg = '没有找到对应的订单';
    $response = [
      'status' => 'error',
      'msg' => $msg
    ];
    echo json_encode($response);
  }
}
// 输入的信息有误
else {
  $msg = '您输入的信息有误';
  $response = [
    'status' => 'error',
    'msg' => $msg
  ];
  echo json_encode($response);
}
